#include "Pathogen.h"

Pathogen::Pathogen()
	:m_sName("Default"),
	m_iVirulence(0),
	m_iLethality(0),
	m_iVisibility(0),
	m_iMutationPoints(30)
{
	InitManifestations();

}
void Pathogen::InitManifestations()
{
	//This function refers to the Manifestations.txt. It iterates through for 
	//the constant value of MaxManifests and fills an array of manifestations
	//which the function will reference to in calculating its stats.

	//=====VARIABLES
	string ReadValue;									//For storing the string we read in
	bool NumbersAlreadyChosen[MaxManifests] = {0};		//For making sure we don't put multiple manifests in

	srand((unsigned int)time(NULL));					//For choosng a random number
	for(int i = 0; i < MaxManifests; i++){
		ifstream File("Manifestations.txt");							//Open the file and read from the top.
		if(File.is_open()){												//Only proceed if the file is open
			int ManifestsAmount;	File >> ManifestsAmount;			//Grab the first value, this is number of Manifests
			//==QUANTIFY SEARCH
			int iRandSelect = std::rand()%ManifestsAmount +1 + Index;	//Choose a random number within the proper range.
			while(NumbersAlreadyChosen[iRandSelect] == true)			//If the manifestation has already been picked...
				iRandSelect = std::rand()%ManifestsAmount +1 + Index;	//...try another
			NumbersAlreadyChosen[iRandSelect]  = true;					//Saves so we never choose this manifest again.
			//TODO: Put a catch if ManifestsAmount < MaxManifests
			stringstream Search;	Search << iRandSelect;				//This number is now what we're searching for.
			//==BEGIN SEARCH
			while(!File.eof()){											//While there is more to read from the file
				getline(File,ReadValue,';');							//Grab a line and...
				if (ReadValue.find(Search.str(),0) != string::npos){	//...compare it to our search
					//Grab the values following the Searched values anf fill them into m_AllManifests
					string	Name;				
					string	Desc;			
					getline(File,Name,';');
					getline(File,Desc,';');
					getline(File,ReadValue,';');		int Vir		= atoi(ReadValue.c_str());
					getline(File,ReadValue,';');		int Leth	= atoi(ReadValue.c_str());
					getline(File,ReadValue,';');		int Vis		= atoi(ReadValue.c_str());
					getline(File,ReadValue,';');		int MutCost	= atoi(ReadValue.c_str());
					getline(File,ReadValue,';');		int MutSell	= atoi(ReadValue.c_str());
					getline(File,ReadValue,';');		int RiotCh	= atoi(ReadValue.c_str());
					m_AllManifests[i].SetValues(Name,Desc,Vir,Leth,Vis,MutCost,MutSell,RiotCh);
				}//Endif
			}//Endwhile
			File.close();
		}//Endif
	}//Endfor
};//Endfunction
int Pathogen::BuyManifest(int Element)
{
	/**
	*	Checks the manifest at the given element to see if we do or
	*	don't already own it, if we don't it buys it, if we do it gets
	*	rid of it, for a cost.
	*/
	if(m_iMutationPoints > m_AllManifests[Element].m_iMutationCost)
	{
		if(!m_bMyManifests[Element])
		{
			m_bMyManifests[Element]	= true;
			m_iMutationPoints	-= m_AllManifests[Element].m_iMutationCost;
			m_iVirulence		+= m_AllManifests[Element].m_iVirulenceMod;
			m_iLethality		+= m_AllManifests[Element].m_iLethalityMod;
			m_iVisibility		+= m_AllManifests[Element].m_iVisibilityMod;
			m_iRiotChance		+= m_AllManifests[Element].m_iRiotChanceMod;
			return 1;
		}
	}

	return 0;
}